<template>
  <div>
    <div id="building"></div>
    <div class="fly">
      <van-form @submit="onSubmit">
        <van-field
          v-model="phone"
          name="手机号"
          label="手机号"
          placeholder="手机号"
          :rules="[{ required: true, message: '请填写手机号' }]"
        />
        <van-field
          class="input1"
          v-model="sms"
          clearable
          label="短信验证"
          placeholder="输入验证码"
          :rules="[{ required: true, message: '' }]"
        >
          <template #button>
            <div>
              <van-button v-if="YZM" size="small" type="primary" @click="btn"
                >点击发送</van-button
              >
              <van-button v-else size="small" type="primary" @click="btn"
                >已发送</van-button
              >
            </div>
          </template>
        </van-field>
        <van-field
          v-model="u_pwd"
          type="password"
          name="新密码"
          label="新密码"
          placeholder="新密码"
          :rules="[{ required: true, message: '请填写新密码' }]"
        />

        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit" 
            >提交修改</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  data() {
    return {
      phone: "",
      u_pwd: "",
      sms: "",
      YZM: true,
    };  
  },
  methods: {
    btn() {
      if (this.phone == "") {
        return;
      } else {
        if (/^1[3-9]\d{9}$/.test(this.phone)) {
          const url = "http://localhost:4000/login";
          this.axios.get(url).then((res) => {
            console.log(res.code);
            this.YZM = false;
            if (!this.sms == res.code) {
              // this.$router.push("/forget");
              Toast.fail("验证码输入错误");
            }
          });
        }
      }
    },
    onSubmit(values) {
      const { phone, u_pwd } = this;
      const url = "/v1/users/reg";
      const params = `phone=${phone}&u_pwd=${u_pwd}`;
      this.axios.post(url, params).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          Toast.success("恭喜,密码修改成功");
          setTimeout(() => {
            this.$router.push("/");
          }, 3000);
        } else {
          console.log("登录失败");
        }
      });
    },
  },
};
</script>

<style scoped>
#building {
  background: url("../assets/images/loginimg.png") center;
  opacity: 0.7;
  width: 100%;
  height: 100%;
}

.fly {
  position: absolute;
  width: 80%;
  left: 50%;
  transform: translateX(-50%);
  bottom: 100px;
  z-index: 100;
}
input:-internal-autofill-selected {
  background-color: -internal-light-dark(
    rgba(255, 255, 255, 0),
    rgba(70, 90, 126, 0)
  ) !important;
}
div/deep/.van-cell {
  background-color: transparent !important;
  border: 1px solid #fff8f8;
  margin-top: 20px;
  border-radius: 25px;
  width: 100%;
  height: 100px;
}
.van-cell::after {
  border-bottom: 0 solid #000;
}
div/deep/.van-field__body input {
  transform: translateY(-3px) !important;
  color: #fff;
  
  line-height: 60px;
  text-align: left;
}
div/deep/.van-field__error-message {
  transform: translateY(-20px);
}
div/deep/.van-button--small {
  transform: translate(20px, -5px) !important;
}
div/deep/.input1 .van-cell__value.van-field__value input.van-field__control {
  transform: translateY(-6px) !important;
}

div/deep/.van-field__label {
  
  color: #fff;
  line-height: 50px;
  text-align: center;
}
.van-button--info {
  width: 100%;
  
  color: #fff;
  
  background-color: #e81964;
  border: 1px solid #e81964;
}

</style>
